import { ref } from "vue";
import { getOrderDetail } from "@/api/customerPage/order";
import { getWorkerOrderDetail } from "@/api/workerPage/order";
import type { OrderParams } from "@/types/order";

export const useOrder = () => {
    // 查询订单
    const orderDetail = ref<OrderParams>({
        workType: "",
        workDate: "",
        workPlace: "",
        status: 0,
        feeType: "",
        peopleNum: 0,
        workHour: "",
        unitPrice: "",
        orderDsg: "",
        money: 0,
        pay: 0,
        couponId: "",
        customerImages: "",
        lat: 0,
        lng: 0,
        userIp: "",
        customerMobile: "",
        address: "",
        introduction: "",
        couponMoney: 0
    })
    // 查询客户订单详情
    const getOrderInfo = async (orderId: string) => {
        try {
            const res: any = await getOrderDetail(orderId)
            if (res.data) {
                orderDetail.value = res.data
            }
        } catch (error) {
            console.log(error);
        }
    }
    // 查询师傅订单详情
    const getWorkerOrderInfo = async (orderId: string) => {
        try {
            const res: any = await getWorkerOrderDetail(orderId)
            if (res.data) {
                orderDetail.value = res.data
            }
        } catch (error) {
            console.log(error);
        }
    }
    return { orderDetail, getOrderInfo, getWorkerOrderInfo }
}